home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / CURSOR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-26  |  4.0 KB  |  146 lines

  1. /********************************************
  2.     file: cursor.c
  3.     utility:
  4.     date: 1989
  5.     author: Jim Charlton
  6.     modifications:
  7.         1996: C. Moreau: 
  8.     comments: 
  9. *********************************************/
  10.  
  11. /********************************************
  12.     includes
  13. *********************************************/
  14. #ifdef __PUREC__ 
  15. #include <aes.h>
  16. #include <tos.h>
  17. #include <vdi.h>
  18. #include <compend.h>
  19. #else
  20. #include <aesbind.h>
  21. #include <osbind.h>
  22. #include <vdibind.h>
  23. #endif
  24.  
  25. #include <stdio.h>
  26.  
  27. #include "button.h"
  28. #include "cursor.h"
  29. #include "init.h"
  30. #include "wind.h"
  31.  
  32. /********************************************
  33.     defines
  34. *********************************************/
  35.  
  36. /********************************************
  37.     locals vars declarations & definitions
  38. *********************************************/
  39.  
  40. /********************************************
  41.     globals vars declarations
  42. *********************************************/
  43.     /* offset in char for data in window */
  44. int    xoffset[33]={    0,2,6,8,12,14,18,20,24,26,            \
  45.                     30,32,36,38,42,44,48,50,54,56,            \
  46.                     60,62,66,68,72,74,78,80,84,86,90,92,96};
  47.  
  48. /********************************************
  49.     locals functions declarations
  50. *********************************************/
  51. void draw_cursors(void);
  52.  
  53. /********************************************
  54.     globals functions definitions
  55. *********************************************/
  56. /*
  57.     name: putcur
  58.     utility: put a black box on current character
  59.     comment: 
  60.     parameters: none
  61.     return: none
  62.     date: 1989
  63.     author: Jim Charlton
  64.     modifications:
  65.         1996: C. Moreau: Added NB_DATA_IN_LINE if more data wanted on a line
  66. */
  67. void putcur(void)
  68.     if(thefrontwin && !thefrontwin->form) /*  cursor action for frontwin only */
  69.     {
  70.             /* no of lines can put in window  */
  71.         const long winlines = thefrontwin->work.g_h/gl_hchar;
  72.             /* position of the 1 first data of window in file */
  73.         const long bottomchar = thefrontwin->topchar + (winlines * NB_DATA_IN_LINE) - 1;
  74.     
  75.             /* don't try to draw cursor unless on page */
  76.         if( (thefrontwin->position >= thefrontwin->topchar) &&
  77.                 (thefrontwin->position <= bottomchar) ) 
  78.         {
  79.             int    x,y,w,h;        /* window sizes */
  80.             wind_get(thefrontwin->handle, WF_WORKXYWH, &x, &y, &w, &h);
  81.             
  82.             graf_mouse(M_OFF, 0L);
  83.  
  84.                 /* set the clipping rectangle in case it was not set     */
  85.             pxyarray[0] = x;
  86.             pxyarray[1] = y;
  87.             pxyarray[2] = x + w - 1;
  88.             pxyarray[3] = y + h - 1;
  89.             vs_clip(thefrontwin->graf.handle, CLIP_ON, pxyarray);
  90.     
  91.             vswr_mode(thefrontwin->graf.handle, MD_XOR);
  92.  
  93.             draw_cursors();
  94.  
  95.             vswr_mode(thefrontwin->graf.handle, MD_REPLACE);
  96.  
  97.                 /* unset the clipping rectangle     */
  98.             vs_clip(thefrontwin->graf.handle, CLIP_OFF, pxyarray);
  99.  
  100.             graf_mouse(M_ON, 0L);
  101.         }
  102.     }
  103. }
  104.  
  105. /********************************************
  106.     locals functions definitions
  107. *********************************************/
  108.  
  109. /*
  110.     name: draw_cursors
  111.     utility: draw cursors in window
  112.     comment: inpired of XXed code
  113.     parameters:
  114.     return:
  115.     date: 14 dec 96
  116.     author: C. Moreau
  117.     modifications:
  118. */
  119. void draw_cursors(void)
  120. {
  121.         /* position of data in window */
  122.     const int pos = (int)(thefrontwin->position - thefrontwin->topchar);
  123.         /* column position number in window */
  124.     const int column = pos % NB_DATA_IN_LINE;
  125.         /* line position number in window */
  126.     const int line = pos / NB_DATA_IN_LINE;
  127.  
  128.     thefrontwin->xcur = thefrontwin->work.g_x + (xoffset[column]+1)*gl_wchar - 1;
  129.     thefrontwin->ycur = thefrontwin->work.g_y + line*gl_hchar + 1;
  130.  
  131.         /* cursor un HEXA part */
  132.     pxyarray[0] = thefrontwin->xcur;
  133.     pxyarray[1] = thefrontwin->ycur;
  134.     pxyarray[2] = thefrontwin->xcur + HEX_DATA_WSIZE*gl_wchar - 1;
  135.     pxyarray[3] = thefrontwin->ycur + gl_hchar - 1;
  136.     v_bar(thefrontwin->graf.handle, pxyarray);
  137.  
  138.         /* cursor in ASCII part */
  139.     pxyarray[0] = thefrontwin->work.g_x + (ASCII_DATA_OFFSET+column+1)*gl_wchar - 1;
  140. /*    pxyarray[1] = thefrontwin->ycur; */
  141.     pxyarray[2] = pxyarray[0] + ASCII_DATA_WSIZE*gl_wchar - 1;
  142. /*    pxyarray[3] = thefrontwin->ycur + gl_hchar - 1; */
  143.     v_bar(thefrontwin->graf.handle, pxyarray);
  144. }
  145.